package com.neusoft.EYSystem.controller;

import com.neusoft.EYSystem.dao.BedUsageDAO;
import com.neusoft.EYSystem.po.*;
import com.neusoft.EYSystem.service.BedUsageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bedUsage")
public class BedUsageController {
    @Autowired
    private BedUsageService bedUsageService;

    @Autowired
    private BedUsageDAO bedUsageDAO;

    @GetMapping("/page")
    public PageResponseBean<List<ClientBedUsage>> bedUsagePage(String name, String checkinDateStart, String checkinDateEnd, String status, Long page, Long size) {
        return bedUsageService.bedUsagePage(name, checkinDateStart, checkinDateEnd, status, page, size);
    }

    @PostMapping("/updateET")
    public ResponseBean<Integer> updateEndTime(@RequestBody BedUsage bedUsage) {
        ResponseBean<Integer> response = new ResponseBean<>();
        try {
            int result = bedUsageDAO.updateById(bedUsage);
            if (result > 0) {
                response.setStatus(200);
                response.setMsg("结束时间更新成功");
                response.setData(result);
            } else {
                response.setStatus(404);
                response.setMsg("结束时间更新失败，可能记录不存在");
            }
        } catch (Exception e) {
            response.setStatus(500);
            response.setMsg("结束时间更新失败: " + e.getMessage());
        }
        return response;
    }

    @PostMapping("/exchange")
    public ResponseBean<Integer> exchangeBed(BedUsage bedUsage) {
        return bedUsageService.exchangeBed(bedUsage);
    }

}
